from appium.webdriver.common.appiumby import AppiumBy

from base.wecom_app import WeComApp
from utils.log_utils import logger


class AddressListPage(WeComApp):
    _SEARCH_BTN = AppiumBy.XPATH, "//*[@text='木易公司']/../../../../child::*[3]/*[1]"
    _CONTACT_NAMES = AppiumBy.XPATH, "//*[@text = '可能的同事']/following-sibling::android.view.ViewGroup//*[@class='android.widget.TextView']"

    def goto_add_member_page(self):
        from page.add_member_page import AddMemberPage
        # 调用滑动寻找元素方法，向下滑动页面定位添加成员按钮并点击
        logger.info("点击【添加成员】按钮")
        self.swipe_find_and_click('添加成员')

        # 跳转添加成员页面
        return AddMemberPage(self.driver)

    def goto_address_list_search_page(self):
        logger.info("点击【搜索】按钮")
        self.find_and_click(*self._SEARCH_BTN)

        # 进入搜索页面
        from page.address_list_search_page import AddressListSearchPage
        return AddressListSearchPage(self.driver)

    def get_names(self):
        logger.info("获取联系人姓名列表")
        names = self.get_texts(*self._CONTACT_NAMES)

        return names
